﻿using System;
using System.Windows.Forms;
using System.Xml;
using ExpertSystem.Domains;

namespace ExpertSystem.Views
{
    public partial class Form1 : Form
    {
        private Ruleset _a;
        private string _filename;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click_2(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _a.StartConsultation();
        }

        private void режимЭкспертаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExpertView d = new ExpertView(_a.Rules,_a.Ships,_a.Variables);
            d.ShowDialog();
        }

        private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                _a = new Ruleset();
                var document = new XmlDocument();
                _filename = openFileDialog1.FileName;
                document.Load(openFileDialog1.FileName);
                _a.ReadRuleSet(document);
                режимыToolStripMenuItem.Enabled = true;
            }
        }

        private void режимКонсультацииToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _a = new Ruleset();
            var document = new XmlDocument();
            document.Load(_filename);
            _a.ReadRuleSet(document);
            _a.StartConsultation();
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void асинхроннаяКонсультацияToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PreConsultation preConsultation = new PreConsultation();
            preConsultation.ShowDialog();
            if (preConsultation.DialogResult == DialogResult.OK)
            {
                AsyncRuleset asyncRuleset = new AsyncRuleset(_a.Name);
                var document = new XmlDocument();
                document.Load(_filename);
                asyncRuleset.ReadRuleSet(document);
                StepUpConsultation stepUpConsultation = new StepUpConsultation(asyncRuleset);
                asyncRuleset.Castomize += stepUpConsultation.CastomizeView;
                asyncRuleset.RuleActive += stepUpConsultation.RuleActivated;
                stepUpConsultation.Show();
            }
            //режимыToolStripMenuItem.Enabled = true;
        }

        private void справкаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HelpView hv = new HelpView();
            hv.ShowDialog();
        }

        private void режимыToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void выходToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

     
    }
}
